//
//  ContactAddress.swift
//  AddressBookKit
//
//  Created by tkgz on 16/5/27.
//  Copyright © 2016年 taoJ. All rights reserved.
//

import UIKit
import AddressBookUI

class ContactAddress: NSObject {
    // 目前获取不到
    var localizedAddressLabel = ""
    var address = ""
    var country = ""
    var state = ""
    var city = ""
    var street = ""
    var contryCode = ""
    
    init(addressValues: ABMutableMultiValue, index: Int) {
        let address = ABMultiValueCopyValueAtIndex(addressValues, index)
        let addrNSDict: NSMutableDictionary = address.takeRetainedValue()
            as! NSMutableDictionary
        country = addrNSDict[kABPersonAddressCountryKey as String] as? String ?? ""
        state = addrNSDict[kABPersonAddressStateKey as String] as? String ?? ""
        city = addrNSDict[kABPersonAddressCityKey as String] as? String ?? ""
        street = addrNSDict[kABPersonAddressStreetKey as String] as? String ?? ""
        contryCode = addrNSDict[kABPersonAddressCountryCodeKey as String] as? String ?? ""
    }
    
    class func contactAddresss(addressValues: ABMutableMultiValue) -> [ContactAddress] {
        var contactAddresss: [ContactAddress] = []
        for i in 0 ..< ABMultiValueGetCount(addressValues){
           let contactAddress = ContactAddress(addressValues: addressValues, index: i)
            contactAddresss.append(contactAddress)
        }
        
        return contactAddresss
    }
    
    deinit {
        print("ContactAddress: deinit")
    }
}
